﻿using LevelEditor.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Xceed.Wpf.Toolkit.PropertyGrid;

namespace LevelEditor.View.UserControls
{
    /// <summary>
    /// Interaction logic for PropertiesPanel.xaml
    /// </summary>
    public partial class PropertiesPanel : UserControl
    {
        // Fields

        private Scene scene;
        private PropertyDefinitionCollection sceneProps;
        private GameSprite selectedSprite;
        private PropertyDefinitionCollection spriteProps;

        // Methods
        public PropertiesPanel()
        {
            this.InitializeComponent();
            this.spriteProps = new PropertyDefinitionCollection();

            spriteProps.Add(new PropertyDefinition { Name = "Name" });
            spriteProps.Add(new PropertyDefinition { Name = "X" });
            spriteProps.Add(new PropertyDefinition { Name = "Y" });
            spriteProps.Add(new PropertyDefinition { Name = "Width" });
            spriteProps.Add(new PropertyDefinition { Name = "Height" });
            spriteProps.Add(new PropertyDefinition { Name = "Fill" });

            this.sceneProps = new PropertyDefinitionCollection();

            sceneProps.Add(new PropertyDefinition{ Name = "BackgroundColor"  });
            sceneProps.Add(new PropertyDefinition{ Name = "Width"  });
            sceneProps.Add(new PropertyDefinition{ Name = "Height"  });
            sceneProps.Add(new PropertyDefinition{ Name = "GridSquareSize"  });
        }

        public void ShowSceneProperties()
        {
            this.selectedSprite = null;
            this._propertyGrid.PropertyDefinitions = this.sceneProps;
            this._propertyGrid.SelectedObject = this.scene;
        }

        // Properties
        public Scene Scene
        {
            get
            {
                return this.scene;
            }
            set
            {
                this.scene = value;
            }
        }

        public GameSprite SelectedSprite
        {
            get
            {
                return this.selectedSprite;
            }
            set
            {
                this.selectedSprite = value;
                if (value != null)
                {
                    this._propertyGrid.PropertyDefinitions = this.spriteProps;
                    this._propertyGrid.SelectedObject = this.selectedSprite;
                }
                else
                {
                    this.ShowSceneProperties();
                }
            }
        }
    }


}
